﻿<%@ Page Language="C#" Title="构造物页面" MasterPageFile="~/W_View/PageMaster.Master" CodeBehind="B_SturcturePage.aspx.cs" Inherits="STHPMS1.Web.W_View.Basis.B_SturcturePage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <%= UiHelper.RefJsFileHtml("/Scripts/Jquery/ajaxfileupload.js")%>
    
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/Enum.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/JsPage.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/Appearance.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/TypeScript/Bussiness.js")%>
    
    <script>
        //导入的点击事件
        function impt() {
            $("#linkUpload").text("上传");

            $('#dlgImport').dialog('open');
        }

        function closeFile() {
            $("#linkUpload").text("上传");
            $('#dlgImport').dialog('close');
            $("#fileHid").val('');//清空隐藏域
        }
        //上传
        function ajaxFileUpload() {
            $.ajaxFileUpload
            (
                {
                    url: '/api/sturcture/uploadFile', //用于文件上传的服务器端请求地址
                    secureuri: false, //是否需要安全协议，一般设置为false
                    fileElementId: 'file1', //文件上传域的ID
                    dataType: 'string', //返回值类型 一般设置为json
                    success: function (data)  //服务器成功响应处理函数
                    {
                        var file = data.replace('<pre>', '').replace('</pre>', '');
                        //写入隐藏域
                        $("#fileHid").val(file);
                        $("#linkUpload").text("上传成功");
                        //alert($("#fileHid").val())
                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert(e);

                    }
                }
            )
            return false;
        }
        //上传文件验证
        function upLoad() {
            if ($("#linkUpload").text() == "上传") {
                var file = $("#file1").val();//上传文件
                if (file == "") {
                    alert("请选择上传数据");
                    return;
                }
                else {
                    var extStart = file.lastIndexOf(".");
                    var ext = file.substring(extStart, file.length).toUpperCase();
                    if (ext != ".XLS" && ext != ".XLSX") {
                        alert("请上传有效Excel文件");
                        return;
                    }
                }
                ajaxFileUpload();
            }
        }
        //导入处理
        function saveFile() {
          

            var file = $("#fileHid").val();//上传后的Excel路径
            if (file == "") {
                alert("请上传数据文件");
                return;
            }
            $.messager.progress({
                title: '请等待',
                msg: '正在处理中...'
            });
            $.ajax({
                url: "/api/sturcture/saveFile?file=" + encodeURI(file),
                type: "post",
                
                success: function (msg) {
                    $.messager.progress('close');
                    $("#fileHid").val('');//清空隐藏域
                    $('#dlgImport').dialog('close');

                    _view.loadDataGrid();
                },

                error: function (msg) {
                    //错误处理
                    $.messager.alert('错误提示', msg.responseText, "error");
                    closeFile();
                }
            });
        }

    </script>

    <script type="text/javascript">      

       

        var _view = new JsPage();
        var _css = new Appearance();
        var _bus = new Bussiness();

        function onAddClick() {
            _view.AddAction();
        }
        function onEditClick() {
            _view.EditAction();
        }
        function onRemoveClick() {
            _view.RemoveAction();
        }
        function onSumbitClick() {
            _view.sumbitForm();
        }
        function onCloseClick() {
            _view.closeDialog();
        }

        function onSearchClick(n, o) {
            var road = $('#cmbSearch').combobox("getValue");

            var data = [];
            data.push({ key: "road", value: road });

            _view.SearchAction(data);
        }

        $(function () {
            $("#btnAdd").on("click", onAddClick);
            $("#btnEdit").on("click", onEditClick);
            $("#btnDel").on("click", onRemoveClick);
            $("#btnSave").on("click", onSumbitClick);
            $("#btnCancel").on("click", onCloseClick);
            $("#btnImpt").on("click", impt);
            $("#btnUpload").on("click", saveFile);
            $("#btnQuit").on("click", closeFile);
            $("#cmbSearch").combobox({ onChange: onSearchClick });
            $("#Sttype_Dictid").combobox({ onSelect: change_sttype });
            $("#Beginmp").numberbox({ onChange: change_mp });
            $("#Endmp").numberbox({ onChange: change_mp });
            
            _view.setForm($('#fm'))
                .setDialog($('#dlg'))
                .setDataGrid($('#dg'))
                .loadDataGrid("/api/sturcture");
        })

        function change_mp(n, o) {
            var beginmp = $('#Beginmp').textbox("getValue");
            var endmp = $('#Endmp').textbox("getValue");
            var sttype = $('#Sttype_Dictid').combobox("getValue");
            if (beginmp && endmp) {

                var data = [];
                var length = (endmp - beginmp).toFixed(2);
                if (length < 0)
                {
                    $.messager.alert('错误提示', "结束桩号要大于起始桩号", "error");
                    $('#Length').textbox("clear");
                    $('#Techclass_Dictid').combobox('clear');
                    return;
                }
                if (isNaN(length))
                    $('#Length').textbox("clear");
                else
                    $('#Length').textbox("setValue", length);

                var item = _bus.calcTeachClass(sttype, length);
                if (item) {
                    data.push(item);
                    $('#Techclass_Dictid').combobox("loadData", data).combobox('select', item.id);
                }
                else {
                    $('#Techclass_Dictid').combobox('clear');
                }
            }
        }

        function change_sttype(rect){ 
            var stfu_url = '/api/data/sturcture?s='+rect.id;
            var tech_url = '/api/data/technical?t='+rect.id;
            $('#Stfuclass_Dictid').combobox('reload', stfu_url).combobox('clear');
            $('#Techclass_Dictid').combobox('clear');
            change_mp();
        }

    </script>    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table id="dg" class="easyui-datagrid content-place"   data-ajaxcached="false"  data-options='{
                  "title": "构造物列表",
                  "toolbar": "#tb",
                  "method": "get",
                  "iconCls": "icon-edit",
                  "width": "auto",
                  "height": "auto",
                  "nowrap": false,
                  "striped": true,
                  "border": true,
                  "collapsible": false,
                  "fit": false,
                  "singleSelect": true,
                  "rownumbers": true,
                  "pagination": true
                }' >
        <thead>
            <tr>
                <th data-options="field:'Struid',editor:'text',width:80,align:'center',hidden:true">构造物编号</th>
                <th data-options="field:'Rdwayid',editor:'text',width:80,align:'center'">路线编号</th>
                <th data-options="field:'Struname',editor:'text',width:80,align:'center' ">构造物名称</th>
                <th data-options="field:'Sttype_Dictid',editor:'numberbox',width:80,align:'center',formatter:formatEnum" >结构类型</th>
                <th data-options="field:'Beginmp',editor:'numberbox',width:80,align:'center',formatter:_css.formatStake ">起点桩号</th>
                <th data-options="field:'Endmp',editor:'numberbox',width:80,align:'center',formatter:_css.formatStake">终点桩号</th>
                <th data-options="field:'Direction_Dictid',editor:'numberbox',width:80,align:'center' ,formatter:formatEnum">行车方向</th>
                <th data-options="field:'Stfuclass_Dictid',editor:'numberbox',width:80,align:'center',formatter:formatEnum" >功能分类</th>
                <th data-options="field:'Length',editor:'numberbox',width:120,align:'center' ">结构长度(m)</th>
                <th data-options="field:'Techclass_Dictid',editor:'numberbox',width:80,align:'center',formatter:formatEnum" >技术等级</th>
                <th data-options="field:'Struwid',editor:'numberbox',width:80,align:'center' ">构造物宽度(m)</th>
                <th data-options="field:'Begindate',editor:'datebox',width:100,align:'center',formatter:_css.formatDate" >通车时间</th>
                <th data-options="field:'His_Version',editor:'numberbox',width:20,align:'center',hidden:true ">养护版本</th>
            </tr>           
        </thead>
    </table>
   
    <div id="tb">
        <a id="btnAdd" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" >添加</a>
        <a id="btnEdit" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" >编辑</a>
        <a id="btnDel" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" >删除</a>
         <a href="/down?type=gzw" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">模板下载</a>
        <a id="btnImpt" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-redo',plain:true" >导入</a>
        <select id="cmbSearch" class="easyui-combobox" style="width:100px" data-options="prompt:'路线编号',url:'/api/roadway/dict',method:'get',valueField:'id',textField:'id',panelHeight:80">
        </select>
    </div>

     <div id="dlg" class="easyui-dialog" title="保存数据" style="width:350px;height:400px;padding:10px" data-options="
                closed:true,
				iconCls: 'icon-save',
				buttons: '#dlg-buttons'
			">
        <form id="fm" method="post" action="/api/sturcture"  class="easyui-form" data-options="novalidate:true">
           <table>			     
                <tr style="display:none">
                    <td>桥梁编号:</td>
                    <td><input name='Struid' class=' easyui-textbox'  /></td>
                </tr>                
                <tr>
                    <td>路线编号:</td>                    
                    <td><input id="Rdwayid" name='Rdwayid'  class="  easyui-combobox" data-options="prompt:'路线编号',required:true,valueField:'Rdwayid',textField:'Name',url:'/api/roadway/all',method:'get',validType:'MaxLength[20]' "/></td>
                </tr>
                <tr>
                    <td>构造物名称:</td>
                    <td><input name='Struname' class=' easyui-textbox' data-options="required:true, validType:'MaxLength[100]'"  /></td>
                </tr>
                <tr>
                    <td>结构类型:</td>
                    <td><input id="Sttype_Dictid" name='Sttype_Dictid'  class="easyui-combobox" data-options="required:true,prompt:'结构类型',valueField:'id',textField:'text',url:'/api/data/sturcture?s=0',method:'get' "/></td>       
                </tr>
                <tr>
                    <td>起点桩号:</td>
                    <td><input id="Beginmp" name='Beginmp' class=' easyui-numberbox' style="width:165px"  data-options="required:true,min:0,precision:2,formatter:_css.formatStake,parser:_css.parserStake" /></td>
                </tr>
                <tr>
                    <td>终点桩号:</td>
                    <td><input id="Endmp" name='Endmp' class=' easyui-numberbox' style="width:165px"  data-options="required:true,min:0,precision:2,formatter:_css.formatStake,parser:_css.parserStake" /></td>
                </tr>
               <tr>
                    <td>行车方向:</td>
                    <td><input id="Direction_Dictid" name='Direction_Dictid' class=' easyui-combobox'  data-options="required:true,prompt:'行车方向',valueField:'id',textField:'text',panelHeight:'auto',url:'/api/data/direction',method:'get'" /></td>
                </tr>
                <tr>
                    <td>功能分类:</td>       
                     <td><input id="Stfuclass_Dictid" name='Stfuclass_Dictid'  class="easyui-combobox" data-options="required:true,prompt:'功能分类',valueField:'id',textField:'text',method:'get' "/>
                          <div  class="drawing">  
                          <div class="easyui-tooltip circle" title="请选择结构类型,程序自动列出对应功能分类"></div>  
                     </div>  
                     </td>
                </tr>
                <tr>
                    <td>结构长度(m):</td>
                    <td><input id="Length" name='Length' class=' easyui-numberbox'  data-options='required:true,readonly:true,min:0,precision:2,formatter:_css.formatNumber' />
                        <div  class="drawing">  
                            <div class="easyui-tooltip circle" title="请选择结构类型,程序通过终点桩号减去起点桩号计算出" ></div>  
                        </div>  
                    </td>
                </tr>
                <tr>
                    <td>技术等级:</td>
                    <td><input id="Techclass_Dictid" name='Techclass_Dictid'  class="easyui-combobox" data-options="readonly:true,prompt:'技术等级',valueField:'id',textField:'text',panelHeight:'auto'"/>
                        <div class="drawing">  
                            <div class="easyui-tooltip circle" title="请选择结构类型,程序通过结构长度计算出" ></div>  
                        </div>  
                    </td>
                </tr>
                <tr>
                    <td>构造物宽度(m):</td>
                    <td><input name='Struwid' class=' easyui-numberbox'  data-options='min:0,precision:2' /></td>
                </tr>
                <tr>
                    <td>通车时间:</td>
                    <td><input name='Begindate' class=' easyui-datebox'  /></td>
                </tr>
                 <tr style="display:none">
                    <td>养护版本:</td>
                    <td><input name='His_Version' class='easyui-numberbox' /></td>
                </tr>
		    </table>
        </form>
    </div>

    <div id="dlg-buttons">
		<a id="btnSave" href="javascript:void(0)" class="easyui-linkbutton" >保存</a>
		<a id="btnCancel" href="javascript:void(0)" class="easyui-linkbutton" >取消</a>
	</div>

     <!--导入数据-->
    <div id="dlgImport" class="easyui-dialog" title="导入数据" style="width: 320px; height: 250px; padding: 10px" closed="true" data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttonsImport'
			">
      
            <table>
               
               
                <tr>
                    <td>导入源:</td>
                    <td>
                      
                        <input id="fileHid" type="hidden" />
                        <input type="file" id="file1" name="file" style="width: 150px"/>
                        <a href="javascript:void(0)" id="linkUpload"  onclick="javascript:upLoad();">上传</a>
                    </td>
                </tr>
            </table>
      
    </div>
    <!--导入数据命令-->
    <div id="dlg-buttonsImport">
        <a id="btnUpload" href="javascript:void(0)" class="easyui-linkbutton" >确定</a>
        <a id="btnQuit" href="javascript:void(0)" class="easyui-linkbutton" >取消</a>
    </div>
</asp:Content>
